package com.greateamd.timetableasy.client.widgets.course;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;
import com.greateamd.timetableasy.domain.Course;

public class CoursePanel extends Composite {
	
	@UiTemplate("CoursePanel.ui.xml")
	interface CoursePanelUIBinder extends UiBinder<Widget, CoursePanel> {}
	private static CoursePanelUIBinder uiBinder = GWT.create(CoursePanelUIBinder.class);
	
	@UiField DateBox dbStart;
	@UiField DateBox dbEnd;
	@UiField TextBox nameTb;
	@UiField TextBox typeTb;
	@UiField Button submitBt;
	
	private Course course;
	
	public CoursePanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	//---------------------------------------------------------------------
	//-------------------------- UI Action	
	private void setPanel(){
		dbStart.setValue(course.getStartDate());
		dbEnd.setValue(course.getEndDate());
		nameTb.setValue(course.getName());
		typeTb.setValue(course.getType());
	}
	

	//---------------------------------------------------------------------
	//-------------------------- Handler
	@UiHandler("submitBt")
	void onSubmitBtClick(ClickEvent e){
		course.setStartDate(dbStart.getValue());
		course.setEndDate(dbEnd.getValue());
		course.setName(nameTb.getValue());
		course.setType(typeTb.getValue());
	}
	
	public void setCourse(Course c){
		course = c;
		setPanel();
	}

	public Course getCourse() {
		return course;
	}
}
